package Demo;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class java5 {
	public static void main(String[] args) throws IOException {
		File file=new File("read.txt");
		sort(file);
		
	}

	private static void sort(File file) throws IOException {
		FileReader fr=new FileReader("read.txt");
		int ch=0;
		String str="";
		while((ch=fr.read())!=-1){
			str=str+(char)ch;
		}
		fr.close();
		List<Integer> list = Arrays.stream(str.split("-"))
				.map(Integer::parseInt)
				.sorted().collect(Collectors.toList());
		FileWriter fw=new FileWriter("read.txt");
		fw.write(String.valueOf(list.get(0)));
		fw.flush();
		for(int i=1;i<list.size();i++){
			fw.write("-"+String.valueOf(list.get(i)));
			fw.flush();
		}
		fw.close();
	}
}
